function export_spikes
%
%
%put out spike data for prism
% we write rows by cell, with columns containing conditions (order of cells
% but could be from commment field)

global CONTROL
fnames = {CONTROL.filename};
bfn = {};
for i = 1:length(fnames)
    bfn{i} = [fnames{i}(1:8)];
end;
fnu = unique(bfn);

ma=cell(length(fnu), 1);
% now find the matching list for each bfn;
for i = 1:length(fnu)
    ma{i} = find(strncmp(fnu(i), fnames, 8) == 1);

end;
pars = {'hwa', 'hwb'};
% now generate a printed list for each cell and parameter we need
conds = {'control', 'rHpTx', 'IKIF', 'IKIF+IKIS', 'IKIS', 'noDC'};

fprintf(1, 'spike, control, rHpTx, IKIF, IKIF+IKIS, IKIS, noDC\n');
for k = 1:length(pars)  % for each of the parameters we want to extrace
    fprintf(1, '\n\nParameter: %s\n', pars{k});
fprintf(1, 'spike %s, control, control, control, rHpTx, rHpTx, rHpTx, IKIF, IKIF, IKIF, IKIF+IKIS, IKIF+IKIS,IKIF+IKIS, IKIS, IKIS,IKIS, noDC, noDC,noDC \n', pars{k});
    for i = 1: length(fnu) % for each file in the list
        sel = ma{i}; % get selection list
        fprintf(1, '%s, ', [fnu{i}]);
        for j = 1: length(sel) % for each entry for that file - in order
            sp = [CONTROL(ma{i}(j)).spike];
            n = [sp.('n')];
            parv = [sp.(pars{k})];
            field = char(strcat(pars{k}, '_sd'));
            parsd = [sp.(field)];
            fprintf(1, '%f, %f, %d, ', parv, parsd, n);
        end;
        fprintf(1, '\n');
    end;
end;
